class Solution {
public:
    string removeDuplicates(string s) {
        string ret;
        for (auto ch : s)
        {
            if (ret.size() && ch == ret.back()) ret.pop_back();
            else ret.push_back(ch);
        }
        return ret;
    }
};

class Solution {
public:
    bool backspaceCompare(string s, string t) {
        return changeStr(s) == changeStr(t);
    }
    string changeStr(string s) {
        string ret;
        for (auto ch : s)
        {
            if (ch != '#') ret += ch;
            else
            {
                if (ret.size()) ret.pop_back();
            }
        }
        return ret;
    }
};